<?php
// +----------------------------------------------------------------------
// | 获取平台产品信息变化通知  
// +----------------------------------------------------------------------
// | TongBaoChun <501468940@qq.com>
// +----------------------------------------------------------------------
// | 2015/09/23
// +----------------------------------------------------------------------
include_once '/var/www/html/new/com.inc.php';
include_once '/var/www/html/new/d/class/abc/PFTCoreAPI.class.php';
if(!isset($_SESSION['sid'])) exit('{"status":"fail","msg":"登陆过期","code":0}');
if(!isset($_REQUEST['act'])) exit('{"status":"fail","msg":"参数错误"}');


switch(trim($_REQUEST['act'])){
	
	// 上下架变化通知
	case 'Prods_Status_Note':
		$pStatus = $_REQUEST['status']+0;
		if($pStatus!=1 && $pStatus!=2) exit('{"status":"fail","msg":"参数错误"}');	
		$cache_file = '/var/www/html/new/d/logs/ProdStatus_'.$pStatus.'.php';
		$cache_arry = file_exists($cache_file) ? include $cache_file:array();
		if(count($cache_arry)==0) exit('{"status":"success","list":"[]","count":0}');
		$resps = array();
		$prods = PFTCoreAPI::salePros(array('apply_limit'=>$pStatus));
		foreach($prods as $row){
			if(isset($cache_arry[$row['pid']])) {
				$sort_time[$row['pid']] = $cache_arry[$row['pid']]['time'];
				$resps[$row['pid']] = $cache_arry[$row['pid']];
			}
		}
		if(count($resps)) array_multisort($sort_time, SORT_DESC, SORT_STRING, $resps);
		echo json_encode(array('status'=>'success','list'=>$resps, 'count'=>count($resps)));
		break;
	// 有效期变化通知
	case 'ProdEffective':
		$cache_file = '/var/www/html/new/d/logs/ProdEffective_u.php';
		$cache_arry = file_exists($cache_file) ? include $cache_file:array();
		if(count($cache_arry)==0) exit('{"status":"success","list":"[]","count":0}');
		$resps = array();
		$prods = PFTCoreAPI::salePros(array('apply_limit'=>$pStatus));
		foreach($prods as $row){
			if(isset($cache_arry[$row['pid']])) {
				$sort_time[$row['pid']] = $cache_arry[$row['pid']]['time'];
				$resps[$row['pid']] = $cache_arry[$row['pid']];
			}
		}
		if(count($resps)) array_multisort($sort_time, SORT_DESC, SORT_STRING, $resps);
		echo json_encode(array('status'=>'success','list'=>$resps, 'count'=>count($resps)));
		break;
	default:exit('{"status":"fail","msg":"参数错误"}');break;
}